home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / grabtext.arc / TEXTVU.C < prev    next >
Text File  |  1990-08-28  |  4KB  |  136 lines

  1. /* loader and demo for .ANS, .TXT, .PTX, or .BSV files in aztec C */
  2. /* TEXTVU.c by bill buckels 1990 */
  3.  
  4. /* these files can be created in the THEDRAW or in GWBASIC, etc.   */
  5. /* this program turns off the cursor, loads the file, waits for a  */
  6. /* key press then turns the cursor on and returns the key value as */
  7. /* an exit code. can be used as a slide show driver or batch menu. */
  8.  
  9. #include <stdio.h>
  10. #include <fcntl.h>
  11. #include <stdlib.h>
  12. #include <io.h>
  13.  
  14. #define SCREENSIZE 4000
  15. unsigned int SCREENSEG= 0xb000;
  16.  
  17. /* this macro converts a base and offset to a far pointer */
  18. #define MK_FP(seg,off) ((char far *)(((long)(seg) << 16) | (off)))
  19.  
  20. struct regs{
  21.     int AX;
  22.     int BX;
  23.     int CX;
  24.     int DX;
  25.     int SI;
  26.     int DI;
  27.     int DS;
  28.     int ES;
  29. }inregs,outregs;
  30.  
  31. main(int argc, char **argv)
  32. {
  33.     int fh,i;
  34.     static char far *crt;
  35.  
  36.     unsigned int byteoff=0,secondoff=1,packet;
  37.     unsigned char byte,bytecount;
  38.     int wordcount,target;
  39.     unsigned char *databuf;
  40.     char combuffer[128];
  41.     unsigned int status = 0;
  42.  
  43.     
  44.     sysint(0x11,&inregs,&outregs); /* get equipment list from the bios */
  45.     /* get display type (bits 4 and 5 of ax) */
  46.     if ((outregs.AX & 0x30) < 0x30)SCREENSEG=0xb800;
  47.  
  48.  
  49. switch(argc)
  50. {
  51.     case 2:
  52.  
  53.     crt = MK_FP(SCREENSEG,0x0000);
  54.     databuf=malloc(SCREENSIZE);
  55.  
  56.                /* clearscreen and turn cursor off */
  57.                       system("cls");
  58.                       inregs.AX = 0x0100;
  59.                       inregs.CX = 0x2000;
  60.                       sysint(0x10,&inregs,&outregs);
  61.  
  62.     fh = open(argv[1],O_RDONLY);
  63.     read(fh,databuf,7);
  64.  
  65.     /********************* beginning of run raw ******************/
  66.     if(databuf[0]== '\xfd' && databuf[1]== 0)
  67.     {
  68.      read(fh,databuf,SCREENSIZE);
  69.      close(fh);
  70.      i=SCREENSIZE+1;
  71.      while(i-->0)*crt++=*databuf++;
  72.      status++ ;
  73.      }
  74.  
  75.   /******************** beginning of run length encoded *************/
  76.  
  77.  if(databuf[0]==0 && databuf[1]==3 && databuf[2]==1 && databuf[3]==16)
  78.     {
  79.      status++;
  80.      read(fh,databuf,121);/* blow the rest of the header */
  81.      target = read(fh,databuf,SCREENSIZE);
  82.      close(fh);
  83.  
  84.     wordcount=0;
  85.     do{ bytecount=1;                          /* start with a seed count */
  86.         byte=databuf[wordcount];
  87.         wordcount++;
  88.                                               /* check to see if its raw */
  89.         if(0xC0 == (0xC0 &byte)){             /* if its not, run encoded */
  90.                     bytecount= 0x3f &byte;
  91.                     byte=databuf[wordcount];
  92.                     wordcount++;
  93.                     }
  94.         for(packet=0;packet<bytecount;packet++){
  95.                    if(byteoff<SCREENSIZE){
  96.                         crt[byteoff]=byte;
  97.                         byteoff+=2;
  98.                         }
  99.                    else{
  100.                         crt[secondoff]=byte;
  101.                         secondoff+=2;
  102.                         }
  103.                     }
  104.                      
  105.         }while(wordcount<target);
  106.         }
  107.  
  108.        /****************** begin run cooked ******************/
  109.    if(status==0)
  110.         {
  111.             sprintf(combuffer,"TYPE %s",argv[1]);
  112.             system(combuffer);
  113.          }
  114.  
  115.    free(databuf);
  116.  
  117.    /*********** then wait for a key press ****************/
  118.  
  119.                       inregs.AX = 0x0000;
  120.                       inregs.DX = 0x0000;
  121.                       sysint(0x16,&inregs,&outregs);
  122.                      /* use sysint to generate int 16h */
  123.                      /* return the low order char */
  124.                      status = outregs.AX&0x00ff;
  125.  
  126.                      /* turn cursor on */
  127.                       inregs.AX = 0x0100;
  128.                       inregs.CX = 0x0607;
  129.                       sysint(0x10,&inregs,&outregs);
  130.  
  131.             default: exit(status);
  132.              }
  133.  
  134. }
  135.  
  136.